function J = jacobian_ellipse(X)
%J = jacobian_ellipse(X)
%   X: [phi1 ... phiN, alpha, a, b, z1, z2]
%   J: Jacobi-Matrix an der Stelle X, nach [Fit96b], S. 72 oben 

X = X';

n_phi = length(X)-5;
phi = X(1:n_phi);
alpha = X(n_phi + 1);
a = X(n_phi +2);
b = X(n_phi +3);
%z = X(end-1:end)';

ca = cos(alpha);
sa = sin(alpha);

cp = cos(phi);
sp = sin(phi);

Q = [ca, -sa; sa ca];
Qp = [-sa, -ca; ca, -sa];

J = zeros(2*n_phi, length(X));
    
temp = -Q * [-a * sp; b * cp];
J(1:2:end,1:n_phi) = diag(temp(1,:));
J(2:2:end,1:n_phi) = diag(temp(2,:));

temp = -Qp * [a*cp; b * sp];
J(1:2:end, n_phi+1) = temp(1,:)';
J(2:2:end, n_phi+1) = temp(2,:)';

temp = -Q * [cp;zeros(size(cp))];
J(1:2:end, n_phi+2) = temp(1,:)';

temp = -Q * [zeros(size(sp));sp];
J(2:2:end, n_phi +3) = temp(2,:)';

J(1:2:end, n_phi +4) = -1;
J(2:2:end, n_phi +5) = -1;
   
    

